'use strict';
import Base from './base.js';
export default class extends Base {
	// 获取图表
	async getchartinfoAction(){

		let now = new Date();
		let shopid = this.shop_userinfo.departmentid;
		let dayu = now.valueOf()/1000-604800;

		let order = this.model('or_shop_order');

		let wh1 = {
			departmentid: shopid,
			addtime: ['>=',dayu]
		}

		// 今日现金收益
		let cash_today = await this.model('or_shop_accountlog').where(wh1).select();

		// 开卡
		wh1.ordertype = 1;
		let card_info = await order.where(wh1).select();

		// 开单
		wh1.ordertype = 2;
		let order_info = await order.where(wh1).select();

		// 充值
		wh1.ordertype = 3;
		let recharge_info = await order.where(wh1).select();


		/*
		* 上月和本月时间段(饼状图数据)
		*/
		let Y = now.getFullYear();
		let M = now.getMonth();
		// 上月日期（从上月1号 ~ 现在）
		let UT = Math.round(new Date(M==0?(Y-1)+'-12-1':Y+'-'+M+'-1').valueOf()/1000);

		let wh2 = {
			departmentid: shopid,
			addtime: ['>=',UT],
			ordertype: 1
		}

		// 开卡
		let cinfo = await order.where(wh2).select();

		// 开单
		wh2.ordertype = 2;
		let oinfo = await order.where(wh2).select();

		// 充值
		wh2.ordertype = 3;
		let rinfo = await order.where(wh2).select();

		
		let data = {
			cinfo : cinfo,
			oinfo : oinfo,
			rinfo : rinfo,

			cashinfo : cash_today,
			cardinfo : card_info,
			orderinfo : order_info,
			rechargeinfo : recharge_info,
		}
		return this.json(data);
	}
}